package com.ivi.car.module.home.presenter;

import android.arch.lifecycle.Lifecycle;

import com.ivi.car.base.BasePresenter;
import com.ivi.car.bean.home.CarMaintainInfoBean;
import com.ivi.car.bean.home.CarStatusInfoBean;
import com.ivi.car.bean.home.HomeAdvBean;
import com.ivi.car.module.home.model.HomeModel;
import com.ivi.car.module.home.model.IHomeContract;
import com.trello.rxlifecycle2.LifecycleProvider;

import java.util.List;

import io.reactivex.functions.Consumer;

/**
 * Copyright
 * author zhengcheng
 * date 2018/3/7
 * describe
 * history
 */

public class HomePresenter extends BasePresenter<IHomeContract.View>
    implements
      IHomeContract.Presenter {
  private HomeModel homeModel;

  public HomePresenter(IHomeContract.View view, LifecycleProvider<Lifecycle.Event> provider) {
    super(view, provider);
    homeModel = new HomeModel(provider);
  }

  @Override
  public void loadCarStatusInfo() {
    homeModel.loadCarStatusInfo().subscribe(new Consumer<CarStatusInfoBean>() {
      @Override
      public void accept(CarStatusInfoBean carStatusInfoBean) throws Exception {
        mView.showCarStatusInfo(carStatusInfoBean);
      }
    }, new Consumer<Throwable>() {
      @Override
      public void accept(Throwable throwable) throws Exception {

      }
    });
  }

  @Override
  public void loadMaintainInfo() {
    homeModel.loadMaintainInfo().subscribe(new Consumer<List<CarMaintainInfoBean>>() {
      @Override
      public void accept(List<CarMaintainInfoBean> list) throws Exception {
        mView.showMaintainInfo(list);
      }
    }, new Consumer<Throwable>() {
      @Override
      public void accept(Throwable throwable) throws Exception {

      }
    });
  }

  @Override
  public void loadHomeAdv() {
    homeModel.loadHomeAdv().subscribe(new Consumer<List<HomeAdvBean>>() {
      @Override
      public void accept(List<HomeAdvBean> list) throws Exception {
        mView.showHomeAdv(list);
      }
    }, new Consumer<Throwable>() {
      @Override
      public void accept(Throwable throwable) throws Exception {

      }
    });
  }
}
